package com.example.hssmgs.Student;

import com.example.hssmgs.R;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.StackView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class show_info extends AppCompatActivity {

    SQLiteDatabase db;
    String student_account;
    String string_id;
    Button go_back;

    @SuppressLint("Range")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.show_info);

        // 获取用户信息
        final Intent about_me_intent = getIntent();
        student_account = about_me_intent.getStringExtra("student_id");
        System.out.println(student_account);
        string_id = "";
        //获取数据库对象
        db = new CommonDatabase().getSqliteObject(show_info.this, "test2.db");

        TextView s_about_account = findViewById(R.id.show_account);
        TextView s_about_sname = findViewById(R.id.show_sname);
        TextView s_about_age = findViewById(R.id.show_age);
        TextView s_about_class = findViewById(R.id.show_class);
        TextView s_about_sex = findViewById(R.id.show_sex);
        TextView s_about_brith = findViewById(R.id.show_brith);
        TextView s_about_clubInfo = findViewById(R.id.show_clubInfo);
        TextView s_about_awards = findViewById(R.id.show_awards);
        TextView s_about_work = findViewById(R.id.show_work);

        @SuppressLint("Recycle") Cursor cursor_about = db.query("student_db",null,"id=?",new String[]{about_me_intent.getStringExtra("student_id")},null,null,null);
        while(cursor_about.moveToNext())
        {
            //将通过id查询到的学生信息显示到界面中
            s_about_account.setText(cursor_about.getString(cursor_about.getColumnIndex("id")));
            s_about_sname.setText(cursor_about.getString(cursor_about.getColumnIndex("sname")));
            s_about_age.setText(cursor_about.getString(cursor_about.getColumnIndex("age")));
            s_about_class.setText(cursor_about.getString(cursor_about.getColumnIndex("class")));
            s_about_sex.setText(cursor_about.getString(cursor_about.getColumnIndex("sex")));
            s_about_brith.setText(cursor_about.getString(cursor_about.getColumnIndex("brith")));
            s_about_clubInfo.setText(cursor_about.getString(cursor_about.getColumnIndex("clubInfo")));
            s_about_awards.setText(cursor_about.getString(cursor_about.getColumnIndex("awards")));
            s_about_work.setText(cursor_about.getString(cursor_about.getColumnIndex("graduationWork")));
        }


        go_back=findViewById(R.id.go_back);
        go_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

    }

}

